home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / src / lib / mib / mibScale.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-17  |  4.1 KB  |  191 lines

  1. #include "mibload.h"
  2. #include "mibwidgets.h"
  3.  
  4. extern Display    *dpy;
  5. extern GC     mib_gc;
  6. static int       scaleflag;
  7.  
  8. /* Code for Scale */
  9. /*****************************************************************************/
  10.  
  11. mib_Widget *mib_create_Scale(mib_Widget *parent, char *name, char *orient,
  12.         int posx, int posy, int width, int height, int mib_fill)
  13. {
  14.   mib_Widget    *temp;
  15.   mib_Scale    *myres;
  16.   Arg         args[20];
  17.   int         n;
  18.  
  19.  
  20.   scaleflag = 0;
  21.   /* create the new widget and add it to the tree */
  22.  
  23.   temp = mib_new_mib_Widget();
  24.   if (mib_fill == WDEFAULT)
  25.     mib_add_backward(temp, parent);
  26.   else
  27.     mib_add_mib_Widget(temp, parent);
  28.  
  29.   myres = (mib_Scale *)malloc(sizeof(mib_Scale));
  30.  
  31.   /* initialize public resources */
  32.  
  33.   if (mib_fill == WDEFAULT)
  34.   {
  35.     temp->name = (char *)malloc(strlen(name)+1);
  36.     strcpy(temp->name,name);
  37.   }
  38.   temp->mib_class = (char *)malloc(10);
  39.   sprintf(temp->mib_class,"Scale");
  40.   temp->mib_class_num = MIB_SCALE;
  41.   temp->width = width;
  42.   temp->height = height;
  43.   temp->topOffset = posy;
  44.   temp->leftOffset = posx;
  45.   temp->bottomOffset = 0;
  46.   temp->rightOffset = 0;
  47.   temp->topAttachment = 1;
  48.   temp->leftAttachment = 1;
  49.   temp->bottomAttachment = 0;
  50.   temp->rightAttachment = 0;
  51.  
  52.   temp->mib_allowresize = 1;
  53.  
  54.   /* initialize private resources */
  55.  
  56.   temp->myres = (void *)myres;
  57.   myres->orientation = 0;
  58.  
  59.   /* create Xt widget */
  60.  
  61.   n = 0;
  62.  
  63.   if (mib_fill == WDEFAULT)
  64.   {
  65.     XtSetArg (args[n], XmNleftAttachment, XmATTACH_FORM); n++;
  66.     XtSetArg (args[n], XmNleftOffset, posx);n++;
  67.     XtSetArg (args[n], XmNtopAttachment, XmATTACH_FORM); n++;
  68.     XtSetArg (args[n], XmNtopOffset, posy);n++;
  69.     XtSetArg (args[n], XmNwidth, width); n++;
  70.     XtSetArg (args[n], XmNheight, height); n++;
  71.  
  72.   }
  73.  
  74.   XtSetArg (args[n], XmNrubberPositioning, False); n++;
  75.  
  76.  
  77.   if (mib_fill == WDEFAULT)
  78.     if (!strcmp("VertScale",orient))
  79.     {
  80.       XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  81.     }
  82.     else
  83.     if (!strcmp("HorzScale",orient))
  84.     {
  85.       XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
  86.       myres->orientation = 1;
  87.     }
  88.  
  89.   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
  90.   {
  91.     XtSetArg (args[n], XmNshowArrows, False); n++;
  92.     XtSetArg (args[n], XmNsliderSize, 30); n++;
  93.   }
  94.  
  95.   XtSetArg (args[n], XmNrubberPositioning, False); n++;
  96.   XtSetArg (args[n], XmNhighlightThickness, 0); n++;
  97.  
  98.   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
  99.     temp->me = XtCreateManagedWidget(name, xmScrollBarWidgetClass,
  100.                 temp->parent->me, args, n);
  101.   else
  102.     temp->me = XtCreateManagedWidget(name, xmScaleWidgetClass,
  103.                 temp->parent->me, args, n);
  104.  
  105.   if (mib_fill == WEMPTY)
  106.     scaleflag = 1;
  107.  
  108.   if (mib_fill == WEDIT || mib_fill == WDEFAULT)
  109.   {
  110.     mib_apply_eventhandlers(temp->me, temp);
  111.   }
  112.  
  113.   return temp;
  114. }
  115.  
  116. void mib_delete_Scale(mib_Widget *this)
  117. {
  118.   mib_Scale *temp = (mib_Scale *)this->myres;
  119.  
  120.   free(temp);
  121. }
  122.  
  123. void mib_save_Scale(mib_Widget *this, FILE *fout)
  124. {
  125.   mib_Scale *temp = (mib_Scale *)this->myres;
  126.  
  127.   fprintf(fout,"orientation: %d\\n\\\n", temp->orientation);
  128. }
  129.  
  130. int mib_load_Scale(mib_Widget *this, mib_Buffer *fin)
  131. {
  132.   mib_Scale *myres;
  133.   unsigned char *label_text;
  134.   char          res[MI_MAXSTRLEN];
  135.   char          val[MI_MAXSTRLEN];
  136.   Arg           args[5];
  137.   int        n;
  138.   Dimension    myht,mywd;
  139.  
  140.  
  141.   myres = (mib_Scale *)this->myres;
  142.  
  143.   if (!mib_read_line(fin, res, val))
  144.     return 0;
  145.  
  146.   if (!strcmp(res,"orientation"))
  147.   {
  148.     sscanf(val,"%d",&(myres->orientation));
  149.  
  150.     n = 0;
  151.     if (scaleflag)
  152.     {
  153.       if (!myres->orientation)
  154.       {
  155.         XtSetArg (args[n], XmNscaleWidth, this->width); n++;
  156.       }
  157.       else
  158.       {
  159.         XtSetArg (args[n], XmNscaleWidth, this->height); n++;
  160.       }
  161.  
  162.       XtSetValues(this->me, args, n);
  163.  
  164.     }
  165.  
  166.     n = 0;
  167.     switch (myres->orientation) {
  168.         case 0:
  169.         XtSetArg (args[n], XmNorientation, XmVERTICAL); n++;
  170.         break;
  171.         case 1:
  172.         XtSetArg (args[n], XmNorientation, XmHORIZONTAL); n++;
  173.         break;
  174.         default:
  175.         break;
  176.     }
  177.     XtSetValues(this->me, args, n);
  178.  
  179.   }
  180.   else
  181.     return 0;
  182.  
  183.   if (!mib_read_line(fin, res, val))
  184.     return 0;
  185.  
  186.   if (strcmp(res,"EndWidget"))
  187.     return 0;
  188.  
  189.   return 1;
  190. }
  191.